package com.example.music.tools;

import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

public class BCryptTest {
    public static void main(String[] args) {
        //模拟从前段获取密码
        String password = "123456";
        //新建一个 BCryptPasswordEncoder
        BCryptPasswordEncoder bCryptPasswordEncoder = new BCryptPasswordEncoder();
        //对密码进行加密
        String newPassword = bCryptPasswordEncoder.encode(password);
        //输出加密之后的结果
        System.out.println("加密的密码为：" + newPassword);

        //使用matches方法进行密码的效验
        boolean same_Password_result = bCryptPasswordEncoder.matches(password,newPassword);

        //返回TRUE
        System.out.println("加密的密码和正确密码对比结果："+same_Password_result);

        boolean other_Password_result = bCryptPasswordEncoder.matches("456789",newPassword);

        //返回FALSE
        System.out.println("加密的密码和错误密码对比结果:"+other_Password_result);
    }
}
